<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>姓名案例--watch实现</title>
    <script src="../../js/vue.js"></script>
</head>
<body>
    <div id="root">
        姓：<input type="text" v-model:value="firstName"><br><br>
        名：<input type="text" v-model="secondName"><br><br>
        姓名： <span>{{fullName}}</span>
         
    </div> 


    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: '#root',
            data:{
                firstName:'李',
                secondName:'四',
                fullName:"李-四"
            },
            watch:{
                firstName(newValue){
                    this.fullName = newValue+'-'+this.secondName
                },
                secondName(newValue){
                    this.fullName = this.firstName+'-'+newValue
                }
            }
        })
    </script>

</body>
</html>